package org.spring.springboot.app.mail.mail.controller;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import io.swagger.annotations.Api;
import org.spring.springboot.app.mail.mail.service.ISysuBindService;
import org.spring.springboot.app.user.sysuser.service.ISysUserService;
import org.spring.springboot.util.ApiIndex;
import org.spring.springboot.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(description="mail操作接口")
@RestController
public class DemoEmailController{

    @Autowired
    DefaultKaptcha defaultKaptcha;
    @Autowired
    private ISysuBindService emailService;
    @Autowired
    private ISysUserService sysUserService;
    @Autowired
    private RedisUtils redisUtils;
    /**
     * 测试邮件发送
     * email：邮箱账号
     */
  /*  @ApiOperation(value="测试邮件发送", notes="getEntityById")
    @RequestMapping(value = "/api/mail/getTestDemoEmail", method = RequestMethod.GET)
    public R mainEmail(
            @ApiParam(value = "验证码token", required = true) @RequestParam String token,
            @ApiParam(value = "类型值", required = true) @RequestParam(defaultValue = "") String email
    ) {
        R result = new R();
        try {
            //产生验证码
            String generator = new RandomStringGenerator.Builder().withinRange('0','Z').filteredBy(CharacterPredicates.LETTERS,CharacterPredicates.DIGITS).build().generate(4);
            StringBuilder html=new StringBuilder();
            html.append("<html>");
            html.append("<body>");
            html.append("<a>验证码："+generator+"</a>");
            html.append("</body>");
            html.append("</html>");
            //将验证码存入redis
            redisUtils.setString("binding_" + token, generator, 3 * 60, TimeUnit.SECONDS);
            System.out.println(redisUtils.getString("binding"+token));
            emailService.mainEmail("验证码通知",html.toString(),email);
            return result;
        }catch (Exception e){

        }
        return result;
    }*/

}
